from langchain.chains.llm import LLMChain
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import PromptTemplate, ChatPromptTemplate
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B',stream=True)

# chunks = []
# for chunk in model.stream("what color is the sky?"):
#     chunks.append(chunk)
#     print(chunk.content, end="|", flush=True)

_prompt = """
你是一个友好的AI助手。现在回答用户的提问：{question}。
"""
prompt = ChatPromptTemplate.from_template(_prompt)
parser = StrOutputParser()
chain = prompt | model | parser

for chunk in chain.stream({"question": "1+1在什么时候大于0"}):
    print(chunk, end="|", flush=True)